import httpUtils from "./XmlHttpTool";
import NumberView from "./NumberView";
var shopItem2 = cc.Class({
    name: 'shopItemtwo',
    properties: {
       
        shopImageUrl:cc.String,
        shopName:cc.String,
        shopStatus:cc.Integer,
        chargeBtn:cc.Node,
        shopStar:cc.String
    }
});

cc.Class({
    extends: cc.Component,

    properties: {
       
        items: {
            default: [],
            type: shopItem2
        },//代码几个item格子 初始化
        closeShopBtn:cc.Node,
        scrollShopScrollView:cc.Node,
        itemPrefab: cc.Prefab,//预制节点 代表cell内容详情
        markView:cc.Node,
        shopClose:cc.Button,
        topImage:cc.Node,
        headIconImage:cc.Node,
        namelabel:cc.Label,
        userIdlabel:cc.Label,
        numberCompontent:NumberView
    },


    onLoad () {

       
        var that =this
        cc.loader.load({url: "https://h5.taoqi001.com/minigames/mouse_click/mouseImage/shopcharge.png", type: 'png'}, function (err, img) {
          var mylogo  = new cc.SpriteFrame(img); 
  
          that.topImage.getComponent(cc.Sprite).spriteFrame = mylogo;
    
        });
        
        this.markView.on('touchstart', function (event) {
            console.log("点击结算背景层")
          }, this);


        var that =this
        httpUtils.NhttpPost("/marmot/prize_list",{},function(res){
            console.log("星币商城请求成功",res)
           that.items=res
           for (var i = 0; i < that.items.length; ++i) {

            var item = cc.instantiate(that.itemPrefab);
            that.node.addChild(item);
            item.getComponent('startGameitem').init(that.items[i]);

        }
           
        },function(failres){

            console.log("星币商城请求错误",failres)
        })
       
    },

    closeShopClick:function(){

        console.log("关闭购物车")
     
      
        var changebig = cc.scaleTo(0.02,1.2);

        var finish = cc.callFunc(function(){
    
            var that=this
          var changesmail = cc.scaleTo(0.08,1.0);

          var smaillfinish=cc.callFunc(function(){

            that.scrollShopScrollView.active=false

          })

          var seq2 = cc.sequence(changesmail,smaillfinish)
          this.closeShopBtn.runAction(seq2)
       

       }, this);
    
       var seq = cc.sequence(changebig,finish)

       this.closeShopBtn.runAction(seq)


    },
    
    start () {

    },

    init(){
        var that= this
        httpUtils.NhttpPost("/marmot/user_info",{},function(res){

            console.log("用户信息",res)
            that.namelabel.getComponent(cc.Label).string=res["name"]
            that.userIdlabel.getComponent(cc.Label).string="ID:"+res["id"]
            var stars =parseInt(res["ticket_num"])
            that.numberCompontent.setText(stars)
            var _this =that
            cc.loader.load({url: res.avatar, type: 'png'}, function (err, img) {
              var mylogo  = new cc.SpriteFrame(img); 

              _this.headIconImage.getComponent(cc.Sprite).spriteFrame = mylogo;
              _this.headIconImage.width=82
              _this.headIconImage.height=82
              
        
            });
            

        })  
    } 
    
    // update (dt) {},
});